package pe.com.tma.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import pe.com.tma.dao.CarteraDAO;
import pe.com.tma.model.Cartera;
import pe.com.tma.model.Usuario;
import pe.com.tma.util.RtnGeneral;

public class JPACarteraDAO extends GenericDAOJpa<Long, Usuario> implements CarteraDAO {

	private EntityManager em = getEntityManager();
	private RtnGeneral rtn = null;
	
	
	@Override
	public List<Cartera> obtenerCartera(Usuario user) {
		// TODO Auto-generated method stub
		try {
//			if(user == null){
//				user = new Usuario();
//			}
//			user.setIdCliente(1);
			
			Query q = em.createQuery("SELECT c FROM Cartera c Where c.usuario.idCliente = ?1 ");
			q.setParameter(1, user.getIdCliente());
			return q.getResultList();
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}

}
